package com.dailyblue.java.jdbc.pack0325;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

// 面向过程的添加
public class DemoA {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 建立连接
        String url = "jdbc:mysql://localhost:3306/test";
        String user = "root";
        String password = "a123456";
        Connection conn = DriverManager.getConnection(url, user, password);
        // 创建一个传令官
        String sql = "insert into emp values(null,?,?,?,now(),?,?,?,1)";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, "董杭");
        ps.setString(2, "程序员");
        ps.setInt(3, 7975);
        ps.setDouble(4, 12888.0);
        ps.setDouble(5, 100);
        ps.setInt(6, 20);
        // 执行命令
        int row = ps.executeUpdate();
        System.out.println(row + "行收到影响！");
        // 关闭
        ps.close();
        conn.close();
    }
}
